package com.xypw.models;

import java.util.HashMap;

import com.et.ar.ActiveRecordBase;
import com.et.ar.annotations.Column;
import com.et.ar.annotations.Table;

@Table(name = "tb_areacode")
public class AreaCodeInfo extends ActiveRecordBase {
	
	@Column
	private String areaCode;
	@Column
	private int areaLevel;
	@Column
	private String areaName;

	private static HashMap<String,AreaCodeInfo> selfCache = new HashMap<String,AreaCodeInfo>();
	
	public String getAreaCode() {
		return areaCode;
	}

	public void setAreaCode(String areaCode) {
		this.areaCode = areaCode;
	}

	public int getAreaLevel() {
		return areaLevel;
	}

	public void setAreaLevel(int areaLevel) {
		this.areaLevel = areaLevel;
	}

	public String getAreaName() {
		return areaName;
	}

	public void setAreaName(String areaName) {
		this.areaName = areaName;
	}

	public static AreaCodeInfo findByAreaCode(String areaCode) throws Exception{
		AreaCodeInfo  areaCodeInfo = selfCache.get(areaCode);
		
		if( areaCodeInfo == null ){
			areaCodeInfo = AreaCodeInfo.findFirst(AreaCodeInfo.class,
					" areaCode=? ", new Object[] { areaCode });
			selfCache.put(areaCode, areaCodeInfo);
		}
		
		return areaCodeInfo;
	}

	public static HashMap<String,AreaCodeInfo> getSelfCache() {
		return selfCache;
	}
	
}
